﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DBMapping;

namespace PollerConfiguration
{
    public partial class NewSourceForm : Form
    {
        public NewSourceForm()
        {
            InitializeComponent();
        }

        private void NewSourceForm_Load(object sender, EventArgs e)
        {
            using (DBClassesDataContext dc = new DBClassesDataContext())
            {
                
                ddLanguage.DataSource = dc.D_Languages.ToList();
                ddProtocol.DataSource = dc.D_Protocols.ToList();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            using (DBClassesDataContext dc = new DBClassesDataContext())
            {
                D_Source source = new D_Source()
                {
                    copyright = tbCopyright.Text,
                    language = Convert.ToInt32(ddLanguage.SelectedValue),
                    link = tbLink.Text,
                    protocol = Convert.ToInt32(ddProtocol.SelectedValue),
                    title = tbTitle.Text
                };
                dc.D_Sources.InsertOnSubmit(source);
                dc.SubmitChanges();
            }
            this.Close();
        }
    }
}
